#!/bin/bash

echo "🔧 快速修复Prisma客户端生成问题..."

cd /Users/zyu/leo/ignite-fun/backend

echo "📦 确保依赖已安装..."
pnpm install

echo "🔄 重新生成Prisma客户端..."
npx prisma generate

if [ $? -eq 0 ]; then
    echo "✅ Prisma客户端生成成功"
else
    echo "❌ Prisma客户端生成失败"
    exit 1
fi

echo "🗄️ 运行数据库迁移..."
npx prisma migrate deploy

if [ $? -eq 0 ]; then
    echo "✅ 数据库迁移成功"
else
    echo "⚠️  数据库迁移失败，但继续执行..."
fi

echo "🔨 测试构建..."
pnpm run build

if [ $? -eq 0 ]; then
    echo "✅ 构建成功！现在可以重新部署了"
    echo ""
    echo "🚀 运行以下命令重新部署："
    echo "  cd /Users/zyu/leo/ignite-fun"
    echo "  ./production-deploy.sh"
else
    echo "❌ 构建仍然失败"
    echo ""
    echo "🔍 请检查以下可能的问题："
    echo "  1. 数据库连接是否正常"
    echo "  2. .env文件是否配置正确"
    echo "  3. 是否有其他TypeScript错误"
fi
